import tr = egret.sys.tr;

class RewardItem extends egret.Sprite{

    constructor(item:any){
        super();
        this.width = GameData.stageW * 0.6;
        this.height = 105;
        //边框
        let border:egret.Bitmap = utils.createBitmapByName('dj_bg');
        border.width = 90;
        border.height = 90;
        border.anchorOffsetX = border.width/2;
        border.anchorOffsetY = border.height/2;
        border.x = border.width/2;
        border.y = this.height/2;
        this.height/2;
        this.addChild(border);

        let img:eui.Image = new eui.Image();
        img.width = border.width * 0.85;
        img.height = border.height * 0.85;
        img.anchorOffsetX = img.width/2;
        img.anchorOffsetY = img.height/2;
        img.y = this.height/2;
        img.x = border.x;
        img.source = item.prop_img;
        this.addChild(img);

        let name:egret.TextField = utils.createTextField({
            text:item.prop_name,
            textColor:0xFFFFFF,
            size:24,
            height:this.height/2,
            x:img.width/2 + img.x + 30,
        });
        this.addChild(name);

        let count:egret.TextField = utils.createTextField({
            text:'X'+item.count,
            textColor:0xFFC71F,
            height:this.height/2,
            x:name.width + name.x + 5,
        });
        this.addChild(count);

        let content:egret.TextField = utils.createTextField({
            text:item.prop_desc,
            textColor:0xFFFFFF,
            size:21,
            lineSpacing:18,
            textAlign:egret.HorizontalAlign.LEFT
        });
        if(content.width > this.width * 0.8){
            content.width = this.width * 0.8;
        }
        content.x = name.x ;
        content.y = this.height/2;

        let shape:egret.Shape = new egret.Shape();
        shape.width = content.width + 20;
        shape.height = content.height + 20;
        shape.graphics.beginFill(0x000000);
        shape.graphics.drawRoundRect(0,0,shape.width,shape.height,20,20);
        shape.graphics.endFill();
        shape.x = content.x - 10;
        shape.y = content.y - 10;
        this.addChild(shape);
        this.addChild(content);
        if(content.height > this.height/2){
            this.height += (shape.height - this.height/2);
        }
        this.cacheAsBitmap = true;
    }
}